<?php

// 本类由系统自动生成，仅供测试用途
class UserAction extends CommonAction {

    public function index() {

        $user = M('user');
        $rawUsers = $user->select();

        $rawGroups = A('Group')->getAll();
        
        $this->assign('rawUsers', $rawUsers);
        $this->assign('userrole', C('USERROLE'));
        $this->assign('usergroup', $rawGroups);
        $this->assign('pagetitle', 'Splio | User Management');
        $this->assign('userManagementActive', 'active');
        
        $this->display();
    }


    public function doadd() {
        $formData = $_POST;

        $formData['pwd'] = encrypt($formData['pwd']);
        $formData['time'] = time();

        $user = M('user');

        $formData['aid'] = $user -> add($formData);

        echo json_encode($formData);
    }

    public function show() {

    	$user = M('user');
    	$rawUsers = $user->where("enable=1")->select();

    	$this->assign('rawUsers', $rawUsers);
    	$this->assign('pagetitle', 'Splio | Show');
    	$this->assign('ispShowActive', 'active');
    	
    	$this->display();
    }


    public function status() {

        $data = $_POST;
        $aid = array_shift($data);

        $user = M('user');

        $rawUsers = $user->where("aid=$aid")->save($data);

        echo json_encode($rawUsers);
    }


    public function doupdate() {

        $formData = $_POST;

        $aid = array_shift($formData);
        if(isset($formData['pwd']) && $formData['pwd'])
        {
            $formData['pwd'] = encrypt($formData['pwd']);
        }
        
        $user = M('user');

        $result = $user -> where("aid=$aid") -> save($formData);

        echo $result;
    }


    public function doresume() {

     $formData = $_POST;

        $id = array_shift($formData);

        $formData['enable'] = 1;

        $user = M('user');

        $result = $user -> where("id=$id") -> save($formData);

        echo $result;   
    }

}